import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import Login from '../views/Login.vue'
import Register from '../views/Register.vue'
import Routerperiow from '../components/routerperiow.vue'
import appointment from '../components/appointment.vue'
import advance from '../components/advance.vue'
import overtime from '../components/overtime.vue'
import directives from '../components/404/404.vue'
import construction from '../components/construction/construction.vue'
const routes = [
  {
    path: '/',
    name: 'home',
    component: Home,
    meta: {
      requireAuth: true
    },
    // //路由守卫
		// beforeEnter: (to, from, next) => {
		// 	let isLogin = sessionStorage.getItem('isLogin');
		// 	if(isLogin != 0){
		// 		next()
		// 	}else{
		// 		next('/home');
		// 	}
		// },
    children: [
      {
        path: '/',
        component: Routerperiow
      },
      {
        path:'/appointment',
        component:appointment
      },
      {
        path:'/advance',
        component:advance
      },
      {
        path:'/overtime',
        component:overtime
      },
      {
        path:'/404',
        component:directives
      },
      {
        path: '/:catchAll(.*)',
        redirect: '/404'
      },
      {
        path:"/construction",
        component:construction
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/register',
    name: 'register',
    component: Register
  },
  
];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
});

router.beforeEach((to, from, next) => {
  if (!navigator.onLine) { // 如果网络不正常
    next({ name: 'NotFound' }); // 重定向到 404 组件
  } else {
    next(); // 如果网络正常，继续导航
  }
});
export default router;